package  Layouts
{
	import flash.display.Sprite;
	import flash.text.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.system.fscommand;
	
	public class Menu extends Sprite 
	{
		private var text_format:TextFormat;
		private var text1:TextField;
		private var text2:TextField;
		
		private var bg:Sprite = new Sprite();
		private var imgcont:Sprite = new Sprite();
		private var playbutton:Sprite = new Sprite();
		private var exitbutton:Sprite = new Sprite();
		public var play:Boolean = false;
		public var exit:Boolean = false;
		private var par:Main;
		
		public function Menu(parent:Main):void
		{
			this.par = parent;
			addEventListener(Event.ADDED_TO_STAGE, init)			
		}
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			var W:uint = stage.stageWidth;
			var H:uint = stage.stageHeight;
			
			bg.graphics.beginFill(0xFCF089);
			bg.graphics.drawRect(0 , 0, W, H);
			bg.graphics.endFill();
			addChild(bg);
			
			imgcont.graphics.beginFill(0xC99837);
			imgcont.graphics.drawRoundRect( 0, 0, W / 3, W / 3, W / 9);
			imgcont.graphics.endFill();
			addChild(imgcont);
			imgcont.x = W / 3;
			imgcont.y = W / 9;
			
			playbutton.graphics.beginFill(0xC99837);
			playbutton.graphics.drawRoundRect( 0, 0, W * 2/3, H / 8, H / 16);
			playbutton.graphics.endFill();
			addChild(playbutton);
			playbutton.x = W / 6;
			playbutton.y = W * 4 / 9 + H / 16;
			playbutton.buttonMode = true;
			playbutton.useHandCursor = true;
			playbutton.addEventListener(MouseEvent.CLICK, playbutton_click);
			
			exitbutton.graphics.beginFill(0xC99837);
			exitbutton.graphics.drawRoundRect( 0, 0, W * 2/3, H / 8, H / 16);
			exitbutton.graphics.endFill();
			addChild(exitbutton);
			exitbutton.x = W / 6;
			exitbutton.y = W * 4 / 9 + H * 7 / 32;
			exitbutton.buttonMode = true;
			exitbutton.useHandCursor = true;
			exitbutton.addEventListener(MouseEvent.CLICK, exitbutton_click);
			
			text_format = new TextFormat();
			text_format.size = 50;
			
			text1 = new TextField();
			text1.defaultTextFormat = text_format;
			text1.selectable = false;
			text1.autoSize = TextFieldAutoSize.LEFT;
			text1.text = "Jugar";
			playbutton.addChild(text1)
			text1.x = playbutton.width/2 - text1.textWidth/2;
			text1.y = playbutton.height / 2 - text1.textHeight / 2;
			
			text2 = new TextField();
			text2.defaultTextFormat = text_format;
			text2.selectable = false;
			text2.autoSize = TextFieldAutoSize.LEFT;
			text2.text = "Salir";
			exitbutton.addChild(text2)
			text2.x = playbutton.width/2 - text2.textWidth/2;
			text2.y = playbutton.height/2 - text2.textHeight/2;
			
		}
		
		private function playbutton_click(e:MouseEvent):void {
			par.screen_manager.goToScreen("Nivel1");			
		}
		private function exitbutton_click(e:MouseEvent):void {
			fscommand("quit");
		}
	
	}

}